package com.yunfeisoft.business.model;

import com.applet.base.ServiceModel;
import com.applet.sql.record.TransientField;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * ClassName: PmsProductAttribute
 * Description: 商品属性表
 *
 * @Author: Jackie liu
 * Date: 2020-06-02
 */
@Entity
@Table(name = "PMS_PRODUCT_ATTRIBUTE")
public class PmsProductAttribute extends ServiceModel implements Serializable {

    /**
     * Field serialVersionUID: 序列号
     */
    private static final long serialVersionUID = 1L;

    /**
     * 商品属性分类id
     */
    @Column
    private String productAttributeCategoryId;

    /**
     * 名称
     */
    @Column
    private String name;

    /**
     * 属性选择类型：0->唯一；1->单选；2->多选；对应属性和参数意义不同
     */
    @Column
    private Integer selectType;

    /**
     * 属性录入方式：0->手工录入；1->从列表中选取
     */
//    @Column
//    private Integer inputType;

    /**
     * 可选值列表，以逗号隔开
     */
    @Column
    private String inputList;

    /**
     * 排序字段：最高的可以单独上传图片
     */
    @Column
    private Integer sort;

    /**
     * 分类筛选样式：1->普通；2->颜色
     */
//    @Column
//    private Integer filterType;

    /**
     * 检索类型；0->不需要进行检索；1->关键字检索；2->范围检索
     */
//    @Column
//    private Integer searchType;

    /**
     * 相同属性产品是否关联；2->不关联；1->关联
     */
//    @Column
//    private Integer relatedStatus;

    /**
     * 是否支持手动新增；2->不支持；1->支持
     */
    @Column
    private Integer handAddStatus;

    /**
     * 属性的类型；0->规格；1->参数
     */
    @Column
    private Integer type;

    @TransientField
    private String productAttributeCategoryName;

    public String[] getInputListArr() {
        if (StringUtils.isBlank(inputList)) {
            return null;
        }
        return inputList.split(",");
    }

    public String getTypeStr() {
        return ProductAttributeTypeEnum.valueOf(type);
    }

    public String getProductAttributeCategoryId() {
        return productAttributeCategoryId;
    }

    public void setProductAttributeCategoryId(String productAttributeCategoryId) {
        this.productAttributeCategoryId = productAttributeCategoryId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getSelectType() {
        return selectType;
    }

    public void setSelectType(Integer selectType) {
        this.selectType = selectType;
    }

//    public Integer getInputType() {
//        return inputType;
//    }
//
//    public void setInputType(Integer inputType) {
//        this.inputType = inputType;
//    }

    public String getInputList() {
        return inputList;
    }

    public void setInputList(String inputList) {
        this.inputList = inputList;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

//    public Integer getFilterType() {
//        return filterType;
//    }
//
//    public void setFilterType(Integer filterType) {
//        this.filterType = filterType;
//    }
//
//    public Integer getSearchType() {
//        return searchType;
//    }
//
//    public void setSearchType(Integer searchType) {
//        this.searchType = searchType;
//    }
//
//    public Integer getRelatedStatus() {
//        return relatedStatus;
//    }
//
//    public void setRelatedStatus(Integer relatedStatus) {
//        this.relatedStatus = relatedStatus;
//    }

    public Integer getHandAddStatus() {
        return handAddStatus;
    }

    public void setHandAddStatus(Integer handAddStatus) {
        this.handAddStatus = handAddStatus;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getProductAttributeCategoryName() {
        return productAttributeCategoryName;
    }

    public void setProductAttributeCategoryName(String productAttributeCategoryName) {
        this.productAttributeCategoryName = productAttributeCategoryName;
    }

    /**
     * 属性的类型；0->规格；1->参数
     */
    public enum ProductAttributeTypeEnum {

        STANDARD(0, "规格"),
        PARAM(1, "参数");

        private int value;
        private String label;

        private ProductAttributeTypeEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (ProductAttributeTypeEnum loop : ProductAttributeTypeEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }

        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }
}